﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace FamilyTree_v1._0
{
    public partial class ConstructionGenealogy : UserControl
    {
        private Pen pen;
        private Color StringColor;
        private int LineHeight = 60;
        private int d = 22;
        private Graphics g;
        private Person person;
        private frmAddPerson frmAddPerson;
        private User_Control.UserMemberCard1 ucUserMemberCard1_Male;
        private User_Control.UserMemberCard1 ucUserMemberCard1_Female;
        private User_Control.UserMemberCard2 ucUserMemberCard2_Father;
        private User_Control.UserMemberCard2 ucUserMemberCard2_Mother;
        private User_Control.UserMemberCard3 ucUserMemberCard3_listChild;
        private User_Control.UserMemberCard3 ucUserMemberCard3_listWife;
        private User_Control.UserMemberCard3 ucUserMemberCard3_listHusband;
        private DevExpress.XtraEditors.LabelControl lblistWife;
        private DevExpress.XtraEditors.LabelControl lblistHusband;
        DatabaseHelper db;
        public ConstructionGenealogy()
        {
            InitializeComponent();
            db = new DatabaseHelper();
            frmAddPerson = new frmAddPerson();
            ucUserMemberCard1_Male = new User_Control.UserMemberCard1();
            ucUserMemberCard1_Female = new User_Control.UserMemberCard1();
            ucUserMemberCard2_Father = new User_Control.UserMemberCard2();
            ucUserMemberCard2_Mother = new User_Control.UserMemberCard2();
            ucUserMemberCard3_listWife = new User_Control.UserMemberCard3();
            ucUserMemberCard3_listHusband = new User_Control.UserMemberCard3();
            ucUserMemberCard3_listChild = new User_Control.UserMemberCard3();
           lblistWife = new DevExpress.XtraEditors.LabelControl();
           lblistHusband = new DevExpress.XtraEditors.LabelControl();
            pen = new Pen(new SolidBrush(Color.Red));
            StringColor = Color.Red;
            g = this.CreateGraphics();
            lblistHusband.Width = 150;
           lblistWife.Width = 150;
            lblistWife.Text = "Danh sách vợ";
           lblistHusband.Text = "Danh sách chồng";
           lblistWife.ForeColor = Color.Blue;
            lblistHusband.ForeColor = Color.Blue;
          lblistWife.Font = new System.Drawing.Font("Tahoma", 10, FontStyle.Underline);
            lblistHusband.Font = new System.Drawing.Font("Tahoma", 10, FontStyle.Underline);
            ucUserMemberCard1_Male = new User_Control.UserMemberCard1();
            ucUserMemberCard1_Female = new User_Control.UserMemberCard1();
            ucUserMemberCard2_Father = new User_Control.UserMemberCard2();
            ucUserMemberCard2_Mother = new User_Control.UserMemberCard2();
            ucUserMemberCard3_listChild = new User_Control.UserMemberCard3();
            ucUserMemberCard1_Male.function_EventChangeSex = new User_Control.UserMemberCard1.EventChangeSex(changeHusband);
            ucUserMemberCard1_Female.function_EventChangeSex = new User_Control.UserMemberCard1.EventChangeSex(changeWife);
            ucUserMemberCard1_Male.function_EventAdd_Edit = new User_Control.UserMemberCard1.EventAdd_Edit(eventAdd_Edit);
            ucUserMemberCard1_Female.function_EventAdd_Edit = new User_Control.UserMemberCard1.EventAdd_Edit(eventAdd_Edit);
            ucUserMemberCard2_Father.function_EventAdd_Edit = new User_Control.UserMemberCard2.EventAdd_Edit(eventAdd_Edit);
            ucUserMemberCard2_Mother.function_EventAdd_Edit = new User_Control.UserMemberCard2.EventAdd_Edit(eventAdd_Edit);
            ucUserMemberCard1_Male.function_EventDelete = new User_Control.UserMemberCard1.EventDelete(deleteHusband);
            ucUserMemberCard1_Female.function_EventDelete = new User_Control.UserMemberCard1.EventDelete(deleteWife);
            lblistWife.MouseClick+=new MouseEventHandler(showListWife);
            lblistHusband.MouseClick+=new MouseEventHandler(showListHusband);
            ucUserMemberCard1_Female.BackColor = Color.Yellow;
            ucUserMemberCard2_Mother.BackColor = Color.Yellow;
            ucUserMemberCard3_listChild.function_eventAdd_Edit = new User_Control.UserMemberCard3.eventAdd_Edit(eventAdd_Edit);
            ucUserMemberCard3_listWife.function_eventAdd_Edit = new User_Control.UserMemberCard3.eventAdd_Edit(eventAdd_Edit);
            ucUserMemberCard3_listHusband.function_eventAdd_Edit = new User_Control.UserMemberCard3.eventAdd_Edit(eventAdd_Edit);
            Controls.Add(ucUserMemberCard1_Male);
            Controls.Add(ucUserMemberCard1_Female);
            Controls.Add(ucUserMemberCard2_Father);
            Controls.Add(ucUserMemberCard2_Mother);
            Controls.Add(lblistHusband);
            Controls.Add(lblistWife);
            Controls.Add(ucUserMemberCard3_listChild);
            Controls.Add(ucUserMemberCard3_listWife);
            Controls.Add(ucUserMemberCard3_listHusband);
            Init();
        }
        public void Init()
        {
            ucUserMemberCard1_Male.Location = new Point(this.Width / 2 - ucUserMemberCard1_Male.Width - d, ucUserMemberCard2_Father.Height + LineHeight);
            ucUserMemberCard1_Female.Location = new Point(this.Width / 2 + d, ucUserMemberCard2_Father.Height + LineHeight);
            ucUserMemberCard2_Father.Location = new Point(this.Width / 2 - ucUserMemberCard2_Father.Width - d, 0);
            ucUserMemberCard2_Mother.Location = new Point(this.Width / 2 + d, 0);
            lblistWife.Location = new Point(this.Width / 2 + d, ucUserMemberCard1_Female.Location.Y + d + ucUserMemberCard1_Female.Height);
            ucUserMemberCard3_listWife.Location = lblistWife.Location = new Point(this.Width / 2 + d, ucUserMemberCard1_Female.Location.Y + 2*d + ucUserMemberCard1_Female.Height);
            ucUserMemberCard3_listChild.Location = new Point(ucUserMemberCard1_Male.Location.X + (ucUserMemberCard1_Male.Width / 2 - ucUserMemberCard3_listChild.Width / 2), ucUserMemberCard1_Male.Location.Y + ucUserMemberCard1_Male.Height + 2*d);
            ucUserMemberCard3_listWife.Visible = false;
            ucUserMemberCard3_listHusband.Visible = false;
            lblistHusband.Visible = false;
            lblistWife.Visible = true;
            showFather(null);
            showMother(null);
            showHusband(null);
            showWife(null);
            showChild(null);
            lblistWife.Enabled=false;
            ucUserMemberCard1_Female.Enabled = false;
            ucUserMemberCard2_Father.Enabled = false;
            ucUserMemberCard2_Mother.Enabled = false;
            ucUserMemberCard3_listChild.Enabled = false;
            ucUserMemberCard3_listWife.setName("Danh sách vợ");
            ucUserMemberCard3_listWife.setNameAdd("Thêm vợ");
            ucUserMemberCard3_listWife.BackColor = Color.Yellow;
            ucUserMemberCard3_listHusband.setName("Danh sách chồng");
            ucUserMemberCard3_listHusband.setNameAdd("Thêm chồng");
        }
        public void setComponent(int width, int height)
        {
            Width = width;
            Height = height;
            ucUserMemberCard1_Male.Location = new Point(this.Width / 2 - ucUserMemberCard1_Male.Width - d, ucUserMemberCard2_Father.Height + LineHeight);
            ucUserMemberCard1_Female.Location = new Point(this.Width / 2 + d, ucUserMemberCard2_Father.Height + LineHeight);
            ucUserMemberCard2_Father.Location = new Point(this.Width / 2 - ucUserMemberCard2_Father.Width - d, 0);
            ucUserMemberCard2_Mother.Location = new Point(this.Width / 2 + d, 0);
            ucUserMemberCard3_listWife.Location = new Point(this.Width / 2 + d, ucUserMemberCard1_Female.Location.Y + 2*d + ucUserMemberCard1_Female.Height);
            ucUserMemberCard3_listHusband.Location = new Point(this.Width / 2 - d - ucUserMemberCard3_listHusband.Width, ucUserMemberCard1_Male.Location.Y + 2*d + ucUserMemberCard1_Male.Height);
            lblistWife.Location = new Point(this.Width / 2 + d, ucUserMemberCard1_Female.Location.Y + d + ucUserMemberCard1_Female.Height);
            lblistHusband.Location = new Point(this.Width / 2 - d - lblistHusband.Width, ucUserMemberCard1_Male.Location.Y + d + ucUserMemberCard1_Male.Height);
            ucUserMemberCard3_listChild.Location = new Point(ucUserMemberCard1_Male.Location.X + (ucUserMemberCard1_Male.Width / 2 - ucUserMemberCard3_listChild.Width / 2), ucUserMemberCard1_Male.Location.Y + ucUserMemberCard1_Male.Height + 2*d);
        }
        private void ConstructionGenealogy_Paint(object sender, PaintEventArgs e)
        {
            if (person == null)
                drawHusband();
        }
        private void eventAdd_Edit(object sender, EventArgs e)
        {
            frmAddPerson = new frmAddPerson();
            if (person == null)
            {
                frmAddPerson.function_EventSave = new frmAddPerson.EventSave(addHusband);
                frmAddPerson.setMale();
                frmAddPerson.ShowDialog();
            }
            else
            {
                DevExpress.XtraEditors.LabelControl lb = (DevExpress.XtraEditors.LabelControl)sender;
                if (lb.Parent.Name == "UserMemberCard1")
                {
                    User_Control.UserMemberCard1 uc1 = (User_Control.UserMemberCard1)lb.Parent;
                    if (uc1.getSex())
                    {
                        if (uc1.getEmpty())
                        {
                            frmAddPerson.function_EventSave = new frmAddPerson.EventSave(addHusband);
                            frmAddPerson.setMale();
                            frmAddPerson.ShowDialog();
                        }
                        else
                        {
                            if (person.Sex.Value)
                            {
                                frmAddPerson.setPersonInfor(person);
                            }
                            else
                            {
                                Person husband=db.SearchPersonByID(ucUserMemberCard1_Male.getCardID());
                                frmAddPerson.setPersonInfor(husband);    
                            }
                            frmAddPerson.function_EventSave = new frmAddPerson.EventSave(editHusband);
                            frmAddPerson.setMale();
                            frmAddPerson.ShowDialog();
                        }
                    }
                    else
                    {
                        if (uc1.getEmpty())
                        {
                            frmAddPerson.function_EventSave = new frmAddPerson.EventSave(addWife);
                            frmAddPerson.setFemale();
                            frmAddPerson.ShowDialog();
                        }
                        else
                        {
                            if (!person.Sex.Value)
                            {
                                frmAddPerson.setPersonInfor(person);
                            }
                            else
                            {
                                Person wife = db.SearchPersonByID(ucUserMemberCard1_Female.getCardID());
                                frmAddPerson.setPersonInfor(wife);
                            }
                            frmAddPerson.function_EventSave = new frmAddPerson.EventSave(editWife);
                            frmAddPerson.setFemale();
                            frmAddPerson.ShowDialog();
                        }
                    }
                }
                if (lb.Parent.Name == "UserMemberCard2")
                {
                    User_Control.UserMemberCard2 uc2 = (User_Control.UserMemberCard2)lb.Parent;
                    if (uc2.getSex())
                    {
                        if (uc2.getEmpty())
                        {
                            frmAddPerson.function_EventSave = new frmAddPerson.EventSave(addFather);
                            frmAddPerson.setMale();
                            frmAddPerson.ShowDialog();
                        }
                        else
                        {
                            Person father = db.SearchPersonByID(person.IDofFather.Value);
                            frmAddPerson.setPersonInfor(father);
                            frmAddPerson.function_EventSave = new frmAddPerson.EventSave(editFather);
                            frmAddPerson.setMale();
                            frmAddPerson.ShowDialog();
                        }
                    }
                    else
                    {
                        if (uc2.getEmpty())
                        {
                            frmAddPerson.function_EventSave = new frmAddPerson.EventSave(addMother);
                            frmAddPerson.setFemale();
                            frmAddPerson.ShowDialog();
                        }
                        else
                        {
                            frmAddPerson = new frmAddPerson();
                            Person mother = new Person();
                            mother = db.SearchPersonByID(person.IDofMother.Value);
                            frmAddPerson.setPersonInfor(mother);
                            frmAddPerson.function_EventSave = new frmAddPerson.EventSave(editMother);
                            frmAddPerson.setFemale();
                            frmAddPerson.ShowDialog();
                        }
                    }
                }
                if (lb.Parent.Name == "UserMemberCard3")
                {
                    frmAddPerson = new frmAddPerson();
                    frmAddPerson.function_EventSave = new frmAddPerson.EventSave(addChild);
                    frmAddPerson.ShowDialog();
                }
            }  
        }
        private void addMother()
        {
            frmAddPerson.addMember();
            Person mother = new Person();
            mother = frmAddPerson.getPersonInfor();
            db.AddMother(person, mother);
            person.IDofMother = mother.PersonID;
            frmAddPerson.Dispose();
            showMother(mother);
        }
        private void addFather()
        {
            frmAddPerson.addMember();
            Person father = new Person();
            father = frmAddPerson.getPersonInfor();
            db.AddFather(person, father);
            person.IDofFather = father.PersonID;
            frmAddPerson.Dispose();
            showFather(father);
        }
        private void addWife()
        {
            frmAddPerson.addMember();
            Person wife = new Person();
            wife = frmAddPerson.getPersonInfor();
            db.AddMarriage(person.PersonID, wife.PersonID);
            frmAddPerson.Dispose();
            showWife(wife);
        }
        private void addHusband()
        {
            frmAddPerson.addMember();
            if (person == null)
            {
                ucUserMemberCard1_Female.Enabled = true;
                ucUserMemberCard2_Father.Enabled = true;
                ucUserMemberCard2_Mother.Enabled = true;
                lblistWife.Enabled = true;
                ucUserMemberCard3_listChild.Enabled = true;
                person = frmAddPerson.getPersonInfor();
                showHusband(person);
            }
            else
            {
                Person husband = new Person();
                husband = frmAddPerson.getPersonInfor();
                db.AddMarriage(husband.PersonID, person.PersonID);
                showHusband(husband);
            }
            frmAddPerson.Dispose();
        }
        public void addChild()
        {
            frmAddPerson.addMember();
            Person child = new Person();
            child = frmAddPerson.getPersonInfor();
            showChild(child);
            frmAddPerson.Dispose();
        }
        private void editMother()
        {
            frmAddPerson.editMember();
            showMother(frmAddPerson.getPersonInfor());
            frmAddPerson.Dispose();
        }
        private void editFather()
        {
            frmAddPerson.editMember();
            showFather(frmAddPerson.getPersonInfor());
            frmAddPerson.Dispose();
        }
        private void editWife()
        {
            frmAddPerson.editMember();
            if (!person.Sex.Value)
            {
                person = frmAddPerson.getPersonInfor();
                showWife(person);      
            }
            else
            {
                Person wife = new Person();
                wife = frmAddPerson.getPersonInfor();
                showWife(wife);
            }
            frmAddPerson.Dispose();
        }
        private void editHusband()
        {
            frmAddPerson.editMember();
            if (person.Sex.Value)
            {
                person = frmAddPerson.getPersonInfor();
                showHusband(person);
            }
            else
            {  
                Person husband = new Person();
                husband = frmAddPerson.getPersonInfor();
                showHusband(husband);
            }
            frmAddPerson.Dispose();
        }
        private void deleteHusband()
        {

        }
        private void deleteWife()
        {

        }
        public void drawHusband()
        {
            ucUserMemberCard3_listHusband.Visible = false;
            lblistHusband.Visible = false;
            lblistWife.Visible = true;
            ucUserMemberCard3_listChild.Location = new Point(ucUserMemberCard1_Male.Location.X + (ucUserMemberCard1_Male.Width / 2 - ucUserMemberCard3_listChild.Width / 2), ucUserMemberCard1_Male.Location.Y + ucUserMemberCard1_Male.Height + 2 * d);
            g.Clear(this.BackColor);
            g.DrawLine(pen, new Point(ucUserMemberCard2_Father.Location.X + ucUserMemberCard2_Father.Width / 2, ucUserMemberCard2_Father.Location.Y + ucUserMemberCard2_Father.Height), new Point(ucUserMemberCard2_Father.Location.X + ucUserMemberCard2_Father.Width / 2, ucUserMemberCard2_Father.Location.Y + ucUserMemberCard2_Father.Height + LineHeight / 4));
            g.DrawLine(pen, new Point(ucUserMemberCard2_Mother.Location.X + ucUserMemberCard2_Mother.Width / 2, ucUserMemberCard2_Mother.Location.Y + ucUserMemberCard2_Mother.Height), new Point(ucUserMemberCard2_Mother.Location.X + ucUserMemberCard2_Mother.Width / 2, ucUserMemberCard2_Mother.Location.Y + ucUserMemberCard2_Mother.Height + LineHeight / 4));
            g.DrawLine(pen, new Point(ucUserMemberCard2_Father.Location.X + ucUserMemberCard2_Father.Width / 2, ucUserMemberCard2_Father.Location.Y + ucUserMemberCard2_Father.Height + LineHeight / 4), new Point(ucUserMemberCard1_Female.Location.X + ucUserMemberCard2_Mother.Width / 2, ucUserMemberCard2_Mother.Height + LineHeight / 4));
            g.DrawLine(pen, new Point(this.Width / 2, ucUserMemberCard2_Father.Location.Y + ucUserMemberCard2_Father.Height + LineHeight / 4), new Point(this.Width / 2, ucUserMemberCard2_Father.Location.Y + ucUserMemberCard2_Father.Height + LineHeight / 2));
            g.DrawLine(pen, new Point(ucUserMemberCard1_Male.Location.X + ucUserMemberCard1_Male.Width / 2, ucUserMemberCard1_Male.Location.Y), new Point(ucUserMemberCard1_Male.Location.X + ucUserMemberCard1_Male.Width / 2, ucUserMemberCard1_Male.Location.Y - LineHeight / 2));
            g.DrawLine(pen, new Point(this.Width / 2, ucUserMemberCard2_Father.Location.Y + ucUserMemberCard2_Father.Height + LineHeight / 2), new Point(ucUserMemberCard1_Male.Location.X + ucUserMemberCard1_Male.Width / 2, ucUserMemberCard1_Male.Location.Y - LineHeight / 2));
            g.DrawLine(pen, new Point(this.Width / 2 - d, ucUserMemberCard1_Male.Location.Y + ucUserMemberCard1_Male.Height / 2), new Point(this.Width / 2 + d, ucUserMemberCard1_Female.Location.Y + ucUserMemberCard1_Female.Height / 2));
            g.DrawLine(pen, new Point(ucUserMemberCard1_Male.Location.X + ucUserMemberCard1_Male.Width / 2, ucUserMemberCard1_Male.Location.Y + ucUserMemberCard1_Male.Height), new Point(ucUserMemberCard1_Male.Location.X + ucUserMemberCard1_Male.Width / 2, ucUserMemberCard1_Male.Location.Y + ucUserMemberCard1_Male.Height + 2 * d));
            g.DrawString("Vợ", new Font("Arial", 10, FontStyle.Bold), new SolidBrush(StringColor), new PointF(this.Width / 2 - d, ucUserMemberCard1_Male.Location.Y + ucUserMemberCard1_Male.Height / 2 - 15));
            g.DrawString("Con", new Font("Arial", 10, FontStyle.Bold), new SolidBrush(StringColor), new PointF(this.Width / 2 - ucUserMemberCard1_Male.Width / 2 - d, ucUserMemberCard1_Male.Location.Y + ucUserMemberCard1_Male.Height + d / 2));           
        }
        public void drawWife()
        {
            ucUserMemberCard3_listWife.Visible = false;
            lblistHusband.Visible = true;
            lblistWife.Visible = false;
            ucUserMemberCard3_listChild.Location = new Point(ucUserMemberCard1_Female.Location.X + (ucUserMemberCard1_Female.Width / 2 - ucUserMemberCard3_listChild.Width / 2), ucUserMemberCard1_Female.Location.Y + ucUserMemberCard1_Female.Height + 2 * d);
            g.Clear(this.BackColor);
            g.DrawLine(pen, new Point(ucUserMemberCard2_Father.Location.X + ucUserMemberCard2_Father.Width / 2, ucUserMemberCard2_Father.Location.Y + ucUserMemberCard2_Father.Height), new Point(ucUserMemberCard2_Father.Location.X + ucUserMemberCard2_Father.Width / 2, ucUserMemberCard2_Father.Location.Y + ucUserMemberCard2_Father.Height + LineHeight / 4));
            g.DrawLine(pen, new Point(ucUserMemberCard2_Mother.Location.X + ucUserMemberCard2_Mother.Width / 2, ucUserMemberCard2_Mother.Location.Y + ucUserMemberCard2_Mother.Height), new Point(ucUserMemberCard2_Mother.Location.X + ucUserMemberCard2_Mother.Width / 2, ucUserMemberCard2_Mother.Location.Y + ucUserMemberCard2_Mother.Height + LineHeight / 4));
            g.DrawLine(pen, new Point(ucUserMemberCard2_Father.Location.X + ucUserMemberCard2_Father.Width / 2, ucUserMemberCard2_Father.Location.Y + ucUserMemberCard2_Father.Height + LineHeight / 4), new Point(ucUserMemberCard1_Female.Location.X + ucUserMemberCard2_Mother.Width / 2, ucUserMemberCard2_Mother.Height + LineHeight / 4));
            g.DrawLine(pen, new Point(this.Width / 2, ucUserMemberCard2_Father.Location.Y + ucUserMemberCard2_Father.Height + LineHeight / 4), new Point(this.Width / 2, ucUserMemberCard2_Father.Location.Y + ucUserMemberCard2_Father.Height + LineHeight / 2));
            g.DrawLine(pen, new Point(ucUserMemberCard1_Female.Location.X + ucUserMemberCard1_Female.Width / 2, ucUserMemberCard1_Female.Location.Y), new Point(ucUserMemberCard1_Female.Location.X + ucUserMemberCard1_Female.Width / 2, ucUserMemberCard1_Female.Location.Y - LineHeight / 2));
            g.DrawLine(pen, new Point(this.Width / 2, ucUserMemberCard2_Father.Location.Y + ucUserMemberCard2_Father.Height + LineHeight / 2), new Point(ucUserMemberCard1_Female.Location.X + ucUserMemberCard1_Female.Width / 2, ucUserMemberCard1_Female.Location.Y - LineHeight / 2));
            g.DrawLine(pen, new Point(ucUserMemberCard1_Female.Location.X + ucUserMemberCard1_Female.Width / 2, ucUserMemberCard1_Female.Location.Y + ucUserMemberCard1_Female.Height), new Point(ucUserMemberCard1_Female.Location.X + ucUserMemberCard1_Female.Width / 2, ucUserMemberCard1_Female.Location.Y + ucUserMemberCard1_Female.Height + 2 * d));
            g.DrawLine(pen, new Point(this.Width / 2 - d, ucUserMemberCard1_Male.Location.Y + ucUserMemberCard1_Male.Height / 2), new Point(this.Width / 2 + d, ucUserMemberCard1_Female.Location.Y + ucUserMemberCard1_Female.Height / 2));
            g.DrawString("Chồng", new Font("Arial", 10, FontStyle.Bold), new SolidBrush(StringColor), new PointF(this.Width / 2 - d, ucUserMemberCard1_Male.Location.Y + ucUserMemberCard1_Male.Height / 2 - 15));
            g.DrawString("Con", new Font("Arial", 10, FontStyle.Bold), new SolidBrush(StringColor), new PointF(this.Width / 2 + ucUserMemberCard1_Female.Width / 2 - d / 2, ucUserMemberCard1_Female.Location.Y + ucUserMemberCard1_Female.Height + d / 2));
        }
        public void changeHusband()
        {
            if (!ucUserMemberCard1_Male.getEmpty())
            {
                if (!person.Sex.Value)
                {
                    Person husband = db.SearchPersonByID(ucUserMemberCard1_Male.getCardID());
                    person = husband;
                    show(husband);
                    drawHusband();
                }
            }
        }
        public void changeWife()
        {
            if (!ucUserMemberCard1_Female.getEmpty())
            {
                if (person.Sex.Value)
                {
                    Person wife = db.SearchPersonByID(ucUserMemberCard1_Female.getCardID());
                    person = wife;
                    show(wife);
                    drawWife();
                }
            }
        }
        public void showFather(Person father)
        {
            if (father == null)
            {
                ucUserMemberCard2_Father.setEmpty(true);
                ucUserMemberCard2_Father.setSex(true);
                ucUserMemberCard2_Father.setName("Thêm cha");
                ucUserMemberCard2_Father.setAvatar("Resources/male.png");
            }
            else
            {
                ucUserMemberCard2_Father.setEmpty(false);
                ucUserMemberCard2_Father.setSex(true);
                ucUserMemberCard2_Father.Enabled = true;
                ucUserMemberCard2_Father.setName(father.FirstName + " " + father.MiddleName + " " + father.LastName);
            }
        }
        public void showMother(Person mother)
        {
            if (mother == null)
            {
                ucUserMemberCard2_Mother.setEmpty(true);
                ucUserMemberCard2_Mother.setSex(false);
                ucUserMemberCard2_Mother.setName("Thêm mẹ");
                ucUserMemberCard2_Mother.setAvatar("Resources/female.png");
            }
            else
            {
                ucUserMemberCard2_Mother.setEmpty(false);
                ucUserMemberCard2_Mother.setSex(false);
                ucUserMemberCard2_Mother.Enabled = true;            
                ucUserMemberCard2_Mother.setName(mother.FirstName + " " + mother.MiddleName + " " + mother.LastName);
            }
        }
        public void showWife(Person wife)
        {
            if (wife == null)
            {
                ucUserMemberCard1_Female.setSex(false);
                ucUserMemberCard1_Female.setEmpty(true);
                ucUserMemberCard1_Female.setName("Thêm thành viên mới");
                ucUserMemberCard1_Female.setAvatar("Resources/female.png");
            }
            else
            {
                ucUserMemberCard1_Female.Enabled = true;
                ucUserMemberCard1_Female.setEmpty(false);
                ucUserMemberCard1_Female.setSex(false);
                ucUserMemberCard1_Female.setCardID(wife.PersonID);
                ucUserMemberCard1_Female.setName(wife.FirstName + " " + wife.MiddleName + " " + wife.LastName);
                ucUserMemberCard1_Female.setDateOfBirth(wife.DateOfBirth.ToString());
                ucUserMemberCard1_Female.setPlaceOfBirth(wife.PlaceOfBirth);
                ucUserMemberCard3_listWife.addChild(wife.FirstName + " " + wife.MiddleName + " " + wife + " " + wife.LastName);
            }
        }
        public void showHusband(Person husband)
        {
            if (husband == null)
            {
                ucUserMemberCard1_Male.setName("Thêm thành viên mới");
                ucUserMemberCard1_Male.setAvatar("Resources/male.png");
                ucUserMemberCard1_Male.setSex(true);
                ucUserMemberCard1_Male.setEmpty(true);
            }
            else
            {
                ucUserMemberCard1_Male.Enabled = true;
                ucUserMemberCard1_Male.setEmpty(false);
                ucUserMemberCard1_Male.setSex(true);
                ucUserMemberCard1_Male.setCardID(husband.PersonID);
                ucUserMemberCard1_Male.setName(husband.FirstName + " " + husband.MiddleName + " " + husband.LastName);
                ucUserMemberCard1_Male.setDateOfBirth(husband.DateOfBirth.ToString());
                ucUserMemberCard1_Male.setPlaceOfBirth(husband.PlaceOfBirth);
                ucUserMemberCard3_listHusband.addChild(husband.FirstName + " " + husband.MiddleName + " " + husband.LastName);
            }
        }
        public void showChild(Person child)
        {
            if(child!=null)
                ucUserMemberCard3_listChild.addChild(child.FirstName+" "+" "+child.MiddleName+" "+child.LastName);
        }
        public void showListWife(object sender, MouseEventArgs e)
        {
            if (!ucUserMemberCard3_listWife.Visible)
            {
                ucUserMemberCard3_listWife.Visible = true;
            }
            else
            {
                ucUserMemberCard3_listWife.Visible = false;
            }
        }
        public void showListHusband(object sender, MouseEventArgs e)
        {
            if (!ucUserMemberCard3_listHusband.Visible)
            {
                ucUserMemberCard3_listHusband.Visible = true;
            }
            else
            {
                ucUserMemberCard3_listHusband.Visible = false;
            }
        }
        public void show(Person person)
        {
            if (person == null)
            {
                showFather(null);
                showMother(null);
                showHusband(null);
                showWife(null);
            }
            else
            {
                if (person.IDofFather != null)
                {
                    showFather(db.SearchPersonByID(person.IDofFather.Value));
                }
                else
                {
                    showFather(null);
                }
                if (person.IDofMother != null)
                {
                    showMother(db.SearchPersonByID(person.IDofMother.Value));
                }
                else
                {
                    showMother(null);
                }
                if (person.Sex.Value)
                {
                    showHusband(person);
                    Marriage mr = db.SearchMarriageByID(person.PersonID);
                    if (mr != null)
                    {
                        showWife(db.SearchPersonByID(mr.FemaleID));
                    }
                }
                else
                {
                    showWife(person);
                    Marriage mr = db.SearchMarriageByID(person.PersonID);
                    if (mr != null)
                    {
                        showHusband(db.SearchPersonByID(mr.MaleID));
                    }
                }
            }
        }
        public void setPerson(Person person)
        {
            this.person = person;
            show(person);
        }
        public Person getPerson()
        {
            return person;
        }
    }
}